#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <string.h>
#include <netdb.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <sys/socket.h>
#define SERVPORT 9999
struct head
{
	int i;
	int length;
};
int
main(int argc, char *argv[])
{
	int sockfd;
	struct hostent *host;
	struct sockaddr_in serv_addr;
	if(argc < 2)
	{
		argv[1]="127.0.0.1";
	}
	if((host = gethostbyname(argv[1])) == NULL)
	{
		herror("gethostbyname error!");
		return -1;
	}
	if((sockfd = socket(AF_INET, SOCK_STREAM, 0)) == -1)
	{
		perror("socket error!");
		return -1;
	}

	serv_addr.sin_family = AF_INET;
	serv_addr.sin_port = htons(SERVPORT);
	serv_addr.sin_addr =*((struct in_addr*)host->h_addr);
	bzero(&(serv_addr.sin_zero),8);
	if(-1 == connect(sockfd,(struct sockaddr*)&serv_addr,sizeof(struct sockaddr)))
	{
		perror("connect error");
		return -1;
	}
	char buf[512];
	memset(buf, 0, 512);
	int ii = 0;
	struct head h;
	while(1)
	{
		memset(&h, 0, sizeof(struct head));	
		h.i = ii;
		char *bb = "aaa";
		h.length = strlen(bb) + 1;
		printf("%d\n", h.length);
		memcpy(buf, &h, sizeof(struct head));
		if(-1 == send(sockfd, &buf, sizeof(struct head), 0))
		{
			perror("send error");
			return -1;
		}
		ii++;
		memset(buf,0,512);
		sleep(1);
	}
	close(sockfd);
	return 0;
}
